package yunquan.wang.base.service.impl;

import java.util.Date;
import java.util.concurrent.BlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import yunquan.wang.base.constants.AppConstants;
import yunquan.wang.base.log.LogConstants;
import yunquan.wang.base.queue.QueuesHolder;
import yunquan.wang.base.spring.security.SpringSecurityUtils;
import yunquan.wang.modules.base.entity.Operation;

public class ServiceLog {
	private static final 	Logger dbLogger = LoggerFactory.getLogger(AppConstants.DBLOGER_NAME);
	private static  BlockingQueue<Operation> queue;
	public static void log(Class clazz,String paramString,String operationStr,String message)
	{
		if (queue == null) {
			queue = QueuesHolder.getQueue(AppConstants.SERVICE_QUEUE_NAME);
		}
	    Operation operation=new Operation();
		operation.setCreateTime(new Date());
		operation.setInfo(message);
		operation.setModel(clazz.getSimpleName());
		operation.setOperation(operationStr);
		operation.setParameter(paramString);
		operation.setSuccess(true);
		operation.setUserName("1");
		operation.setIpAddr(SpringSecurityUtils.getCurrentUserIp());
		boolean sucess = queue.offer(operation);

		if (sucess) {
			dbLogger.debug("Success put operation into Queues:"+operation.toString());

		} else {
			dbLogger.debug("Failed put operation into Queues:"+operation.toString());
		}
	}
}
